package com.shuiqinling.ww.android.cn00.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.shuiqinling.ww.android.Util.PayHelper;
import com.shuiqinling.ww.android.Util.UIHelper;
import com.shuiqinling.ww.android.cn00.R;
import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

	private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";

	public static String tradeNo;

	private IWXAPI api;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.pay_result);

		api = WeChat.api;
		api.handleIntent(getIntent(), this);
	}

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
		api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
	}

	@Override
	public void onResp(BaseResp resp) {
		Log.d(TAG, "onPayFinish, errCode = " + resp.errCode);

		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
			PayHelper.notifyUnity(String.valueOf(resp.errCode));
//			if (resp.errCode == 0) {
//				UIHelper.ShowToast(getResources().getString(R.string.pay_result_callback_msg_ok));
//			} else {
//				UIHelper.ShowToast(getResources().getString(R.string.pay_result_callback_msg_exit));
//			}
			// UIHelper.ShowToast(this,
			// getString(R.string.pay_result_callback_msg,
			// String.valueOf(resp.errCode)));
			// PayHelper.serverNotify(this, tradeNo, String.valueOf(resp.errCode
			// == 0 ? 8888 : resp.errCode));
			this.finish();
		}
	}
}